package cn.fl.risknew.controller;


import cmm.mid.core.framework.page.DataResultVO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.risknew.service.IRskUlFileLogService;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlFilesRecService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description: 贷后资料补充申请记录表 控制层
 */
@Controller
@RequestMapping("/risknew/rskulfilelog")
public class RskUlFileLogController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(RskUlFileLogController.class);

	/**
	 * RskUlFileLog 服务层BEAN
	 */
	@Autowired
	private IRskUlFileLogService rskUlFileLogService;

	@Autowired
	private ISysUlFilesRecService sysUlFilesRecService;


	/********************
	 * 上传贷后补充资料文件
	 *******************/
	///risknew/rskulfilelog/ulSuppFile.do
	@RequestMapping(value = "/ulSuppFile.do", method = {RequestMethod.POST})
	@ResponseBody
	public Object uploadPrjFile(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_FILE_UPLOAD_SUCC);
		String fileParams = request.getParameter("fileParams");
		String cfgCd = request.getParameter("cfgCd");
		String cfgDtlCd = request.getParameter("cfgDtlCd");
		String orgCd = CurrentThreadContext.getCurrentOrgCd();
		String rskFileId = request.getParameter("rskFileId");
		if (StringUtils.isBlank(rskFileId)) {
			BaseLogUtils.error(logger, "uploadPrjFile", "上传贷后补充资料文件失败,主键ID为空==>cfgCd=" + cfgCd + ",cfgDtlCd=" + cfgDtlCd);
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_FILE_UPLOAD_FAIL);
		} else {
			boolean flag = this.sysUlFilesRecService.addAttchmnt(rskFileId, fileParams, cfgCd, cfgDtlCd, "RSK_UL_FILE_LOG", null, null, null, false, orgCd);
			if (!flag) {
				BaseLogUtils.error(logger, "uploadPrjFile", "上传贷后补充资料文件失败==>rskFileId=" + rskFileId + ",cfgCd=" + cfgCd + ",cfgDtlCd=" + cfgDtlCd + ",file=" + fileParams);
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_FILE_UPLOAD_FAIL);
				return result;
			}
			BaseLogUtils.info(logger, "uploadPrjFile", "上传贷后补充资料文件成功==>rskFileId=" + rskFileId + ",cfgCd=" + cfgCd + ",cfgDtlCd=" + cfgDtlCd);
		}
		return result;
	}

//	/**
//	 * 到列表页面
//	 */
//	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
//	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
//		Long startTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "toListPage", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
//
//		ModelAndView view = new ModelAndView("inf/rskUlFileLog/rskUlFileLogList");
//
//		Long endTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "toListPage", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
//		return view;
//	}
//
//	/**
//	 * 到新增修改页面
//	 */
//	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
//	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
//		Long startTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "toAddPage", "加载新增.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
//
//		ModelAndView view = new ModelAndView("inf/rskUlFileLog/rskUlFileLogAdd");
//
//		Long endTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "toAddPage", "加载新增.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
//		return view;
//	}
//
//	/**
//	 * 到修改页面
//	 */
//	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
//	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
//		Long startTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "toAddPage", "加载修改页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
//
//		String id = request.getParameter("id");
//		ModelAndView view = new ModelAndView("inf/rskUlFileLog/rskUlFileLogModify");
//		view.addObject("id", id);
//		Long endTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "toAddPage", "加载修改.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
//		return view;
//	}
//
//	/**
//	 * 到详情页面
//	 */
//	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET})
//	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
//		Long startTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "toDetailPage", "加载例子详细页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
//
//		String id = request.getParameter("id");
//		ModelAndView view = new ModelAndView("inf/rskUlFileLog/rskUlFileLogDetail");
//		view.addObject("id", id);
//
//		Long endTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "toDetailPage", " 加载例子详细页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
//		return view;
//	}
//
//	/**
//	 * 初始化列表
//	 */
//	@SuppressWarnings("unchecked")
//	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
//	@ResponseBody
//	public Object initList(HttpServletRequest request, HttpServletResponse response) {
//		Long startTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "initList", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
//
//
//		String currentPage = request.getParameter("page");
//		String pageSize = request.getParameter("pagesize");
//		String searchName = request.getParameter("demo.name");
//		Pager page = new Pager();
//		if (StringUtils.isNotEmpty(currentPage)) {
//			page.setCurrentPage(Integer.parseInt(currentPage));
//		}
//
//		if (StringUtils.isNotEmpty(pageSize)) {
//			page.setEveryPage(Integer.parseInt(pageSize));
//		}
//
//		RskUlFileLogQC qc = new RskUlFileLogQC();
//		if (StringUtils.isNotEmpty(searchName)) {
//			//TODO SOMTHING
//		}
//		page.setCondition(qc);
//
//		//TODO SOMETHING
//		Pager pager = new Pager();//this.rskUlFileLogService.searchListPage(page);
//		List<RskUlFileLogVO> list = (List<RskUlFileLogVO>) pager.getResultList();
//		ListPageVO<RskUlFileLogVO> listPage = new ListPageVO<RskUlFileLogVO>(list, pager.getTotalCount());
//		Long endTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "initList", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
//		return listPage;
//	}
//
//	/**
//	 * 新增
//	 */
//	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
//	@ResponseBody
//	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
//		Long startTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "add", "新增对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
//
//		String name = request.getParameter("name");
//		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
//		RskUlFileLogVO entity = null;
//		try {
//			entity = new RskUlFileLogVO();
//			//TODO ADD PARAM
//			Long id = this.rskUlFileLogService.add(entity);
//			result.setData(id);
//			BaseLogUtils.info(logger, "add", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
//		}catch (BaseException ex) {
//			result.setSuccess(BaseConstant.IS_YESNO_NO);
//			result.setInfo(ex.getMessage());
//			BaseLogUtils.info(logger, "add", "新增对象失败,name["+name+"].", CurrentThreadContext.getCurrentUserName(), ex);
//		}catch (Exception ex) {
//			result.setSuccess(BaseConstant.IS_YESNO_NO);
//			result.setInfo("系统错误,请联系管理员!");
//			BaseLogUtils.error(logger, "add", "新增对象失败,name["+name+"].", CurrentThreadContext.getCurrentUserName(), ex);
//		}
//		Long endTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "add", "新增对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
//
//		return result;
//	}
//
//	/**
//	 * 修改
//	 */
//	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
//	@ResponseBody
//	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
//		Long startTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "modify", "修改对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
//
//		String id = request.getParameter("id");
//		String name = request.getParameter("name");
//		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
//		if(StringUtils.isEmpty(id)){
//			result.setSuccess(BaseConstant.IS_YESNO_NO);
//			result.setInfo("数据不存在!");
//			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
//			return result;
//		}
//		RskUlFileLogVO entity = null;
//		try {
//			entity = new RskUlFileLogVO();
//			entity.setId(Long.valueOf(id));
//			//entity.setName(name);
//			//TODO ADD PARAM
//			boolean success = this.rskUlFileLogService.modify(entity);
//			if(!success){
//				result.setSuccess(BaseConstant.IS_YESNO_NO);
//				result.setInfo("修改失败!");
//				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
//			}
//			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
//		} catch (BaseException ex) {
//			result.setSuccess(BaseConstant.IS_YESNO_NO);
//			result.setInfo(ex.getMessage());
//			BaseLogUtils.info(logger, "modify", "修改对象失败,id["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
//		}catch (Exception ex) {
//			result.setSuccess(BaseConstant.IS_YESNO_NO);
//			result.setInfo("系统错误,请联系管理员!");
//			BaseLogUtils.error(logger, "modify", "修改对象失败,id["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
//		}
//
//		Long endTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "modify", "修改对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
//
//		return result;
//	}
//
//	/**
//	 * 删除数据
//	 */
//	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
//	@ResponseBody
//	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
//		Long startTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "remove", "移除对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
//
//		String id = request.getParameter("id");
//		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "删除成功!");
//		if(StringUtils.isEmpty(id)){
//			result.setSuccess(BaseConstant.IS_YESNO_NO);
//			result.setInfo("主键不能为空!");
//			return result;
//		}
//		try {
//			this.rskUlFileLogService.removeById(Long.valueOf(id));
//			BaseLogUtils.info(logger, "removeById", "删除数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
//		}catch (BaseException ex) {
//			result.setSuccess(BaseConstant.IS_YESNO_NO);
//			result.setInfo(ex.getMessage());
//			BaseLogUtils.info(logger, "remove", "移除对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
//		} catch (Exception ex) {
//			result.setSuccess(BaseConstant.IS_YESNO_NO);
//			result.setInfo("系统错误,请联系管理员!");
//			BaseLogUtils.error(logger, "remove", "移除对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
//		}
//
//		Long endTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "remove", "移除对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
//
//		return result;
//	}
//
//	/**
//	 * 得到一条记录
//	 *
//	 * @param request
//	 * @return
//	 * @throws Exception
//	 */
//	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
//	@ResponseBody
//	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
//		Long startTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "getById", "根据主键获取对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
//
//		String id = request.getParameter("id");
//		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
//		if(StringUtils.isEmpty(id)){
//			result.setSuccess(BaseConstant.IS_YESNO_NO);
//			result.setInfo("主键不能为空!");
//			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
//			return result;
//		}
//
//		try {
//			RskUlFileLogVO vo = this.rskUlFileLogService.selectById(Long.valueOf(id));
//			if(null == vo){
//				result.setSuccess(BaseConstant.IS_YESNO_NO);
//				result.setInfo("数据不存在!");
//				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
//			}
//			result.setData(vo);
//			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
//		}catch (BaseException ex) {
//			result.setSuccess(BaseConstant.IS_YESNO_NO);
//			result.setInfo(ex.getMessage());
//			BaseLogUtils.info(logger, "getById", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
//		} catch (Exception ex) {
//			result.setSuccess(BaseConstant.IS_YESNO_NO);
//			result.setInfo("系统错误,请联系管理员!");
//			BaseLogUtils.error(logger, "getById", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
//		}
//
//		Long endTm = System.currentTimeMillis();
//		BaseLogUtils.info(logger, "getById", "根据主键获取对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
//
//		return result;
//	}
}

